#include <stdio.h>
#include <malloc.h>
struct BTNode{
	char data;               // 数据域
	struct BTNode * pLch;   // 左指针
	struct BTNode * pRch;	// 右指针
};
struct BTNode * CreatBTree(void); 
void preTraBTree(struct BTNode * pT);
void inTraBTree(struct BTNode * pT);
void postTraBTree(struct BTNode * pT);
int main(){
	struct BTNode * pT = CreatBTree();
	preTraBTree(pT);
	printf("\n");
	inTraBTree(pT);
	printf("\n");
	postTraBTree(pT);

	return 0;
}
/**
 * 静态构造一个二叉树
 * @Author   smallcatx0
 * @DateTime 2017-03-25
 * @return   struct * BTNode
 */
struct BTNode * CreatBTree(){
	struct BTNode * pA = (struct BTNode *)malloc(sizeof(struct BTNode));
	struct BTNode * pB = (struct BTNode *)malloc(sizeof(struct BTNode));
	struct BTNode * pC = (struct BTNode *)malloc(sizeof(struct BTNode));
	struct BTNode * pD = (struct BTNode *)malloc(sizeof(struct BTNode));
	struct BTNode * pE = (struct BTNode *)malloc(sizeof(struct BTNode));

	pA->data = 'a';
	pB->data = 'b';
	pC->data = 'c';
	pD->data = 'd';
	pE->data = 'e';

	pA->pLch = pB; pA->pRch = pC;
	pB->pLch = pB->pRch = NULL;
	pC->pLch = pD; pC->pRch = NULL;
	pD->pLch = NULL; pD->pRch = pE;
	pE->pLch = pE->pRch = NULL;
	return pA;
}

void preTraBTree(struct BTNode * pT){
	if (pT == NULL)
		return;
	printf("%c ",pT->data);
	if (pT->pLch != NULL)
		preTraBTree(pT->pLch);
	if (pT->pRch !=NULL)
		preTraBTree(pT->pRch);
}

void inTraBTree(struct BTNode * pT){
	if (pT == NULL)
		return;
	if (pT->pLch != NULL)
		inTraBTree(pT->pLch);
	printf("%c ",pT->data);
	if (pT->pRch !=NULL)
		inTraBTree(pT->pRch);
}

void postTraBTree(struct BTNode * pT){
	if (pT == NULL)
			return;
	if (pT->pLch != NULL)
		postTraBTree(pT->pLch);
	if (pT->pRch !=NULL)
		postTraBTree(pT->pRch);
	printf("%c ",pT->data);
}

